Run on Google Cloud
#GoogleCloud
Cloud Run Button : クリックするだけで Git リポジトリのアプリを Cloud Run にデプロイ | Google Cloud Blog
GoogleCloudPlatform/cloud-run-button: Let anyone deploy your GitHub repos to Google Cloud Run with a single click
https://raw.githubusercontent.com/GoogleCloudPlatform/cloud-run-hello/master/assets/celebration.svg
なんなんだ
GoogleCloudPlatform/cloud-run-button のサンプルボタンは
GoogleCloudPlatform/cloud-run-hello をデプロイする
[![Run on Google Cloud](https://deploy.cloud.run/button.svg)](https://deploy.cloud.run/?git_repo=https://github.com/GoogleCloudPlatform/cloud-run-hello.git)
追加の GCP API を有効にしたりはどうする?
デプロイ時のパラメータや環境変数は app.json に置く
ここのprebuild などの hook でなんかやる?
cloud-run-button/api.go at d75fc4841aaf65692a21716db0d59cf525044db3 · GoogleCloudPlatform/cloud-run-button 便利なのある
cloud-run-button/main.go at c6f7e912d25884bec1b75ca79b91724be5ae13b6 · GoogleCloudPlatform/cloud-run-button 内部で使っているだけ、いじれなさそう
run.googleapis.com
containerregistry.googleapis.com
postcreate でやっている例、うまくいくか知らん
nodebars/postcreate.sh at master · jamesward/nodebars
hook の起動タイミング
GoogleCloudPlatform/cloud-run-button@c6f7e91 - cmd/cloudshell_open/main.go#L123 から
Cloud Shell / git clone など
Billing 有効化
Cloud Run & Container Registry API 有効化
リ-っジョン選択やら
prebuild
gcr.io/buildpacks/builder:v1 で build
postbuild
image の push
precreate
gcloud run deploy
hookenvs に SERVICE_URL が追加される
postcreate
なんかを Run on Google Cloud にしてみる
pokutuna/slack-feed-proxy
GoogleCloudPlatform/cloud-run-hello@master - Dockerfile
hello のやつ、参考になる
AppEngine として作っていたけど意外とそのまま動くのでは
ADC 使っているだけ
動きそう
min-instances とか app.json で定義できないのかな?
PR したらぱっと作れそうではあるが
どういう仕組やねん
GET https://deploy.cloud.run/?git_repo=https://github.com/GoogleCloudPlatform/cloud-run-hello.git
https://console.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2FGoogleCloudPlatform%2Fcloud-run-hello.git&cloudshell_image=gcr.io%2Fcloudrun%2Fbutton&shellonly=true へリダイレクト
cloudshell_git_repo: デプロイするリポジトリ
cloudshell_image: gcr.io/cloudrun/button
shellonly: true
このリダイレクト処理をやってるのが cmd/redirector かな
Cloud Shell で開く  |  Google Cloud
Cloud Shell を開くときにカスタム環境として Docker イメージを使える
Cloud Shell コンテナ イメージのカスタマイズ  |  Google Cloud
gcr.io/cloudshell-images/cloudshell をベースイメージとして公開の gcr に置く
cloud-run-button/Dockerfile at master · GoogleCloudPlatform/cloud-run-button
cloudshell_open はどっから実行される?
base の CMD なんかな → そんなこともなさそう
イメージ – Container Registry – Google Cloud Platform
でかすぎ 7.5GB
展開したら 20GB
一通りのツールが入ってるからかねえ
cloudshell_open が何によって kick されてるんだ?
よくわからないので自分で同じイメージビルドして起動してみる
https://console.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2FGoogleCloudPlatform%2Fcloud-run-hello.git&cloudshell_image=gcr.io%2Fpokutuna-playground%2Fbutton&shellonly=true
(この作業の時だけ公開していた)
AppleSilicon やから GOARCH=amd64 せんといかんね...
そして普通に cloudshell_open が起動する
/bin/cloudshell_open を別のバイナリにしてもそれが起動する
バイナリ名変えたらだめ
Cloud Shell 開いた時に実行する決まりなのか? ドキュメントに書いてない気がするが...
/google/devshell/bashrc.google.d/cloudshell_open.sh が実装かな?
Cloud Shell でクエリパラメータが付いていたら cloudshell_open に渡る
これが clone したりする
その Cloud Shell の仕組みにのっかって、Run on Google Cloud ボタンが同名のバイナリを PATH に置いて処理を奪ってる
最初に確認ダイアログはさまるとはいえ、なんか悪用できないのかな
Cloud Shell の PATH → Cloud Shell